﻿using System;
using System.Diagnostics.Contracts;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;

namespace OpenLS.Spreadsheet.UI.Internals
{
    public partial class FontFormatterResources 
    {
        public FontFormatterResources()
        {
            InitializeComponent();
        }

        public static DataTemplate Template
        {
            get
            {
                Contract.Ensures(Contract.Result<DataTemplate>() != null);
                var resources = new FontFormatterResources();
                return (DataTemplate) resources[new DataTemplateKey(typeof (FontFormatter))];
            }
        }


        private void OnFontFamilySelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var selector = (Selector) sender;
            var ff = (FontFormatter) selector.DataContext;
            ff.FontFamily = selector.SelectedItem.ToString();
        }


        private void OnFontStyleSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var selector = (Selector) sender;
            var formatte = (FontFormatter) selector.DataContext;
            formatte.SetStyle(selector.SelectedIndex);
        }


        private void OnFontColorChanged(object sender, SelectionChangedEventArgs e)
        {
            var selector = (Selector) sender;
            var ff = (FontFormatter) selector.DataContext;
            ff.Foreground = (SpreadsheetColor) selector.SelectedItem;
        }

        private void OnSizeSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var selector = (Selector) sender;
            var ff = (FontFormatter) selector.DataContext;
            ff.Size = Convert.ToDouble(selector.SelectedItem);
        }

        private void OnUnderlineChanged(object sender, SelectionChangedEventArgs e)
        {
            var selector = (Selector) sender;
            var ff = (FontFormatter) selector.DataContext;
            ff.Underline = (UnderlineType) (selector.SelectedItem);
        }
    }
}